package com.hehua.web.observer.demo1;

import java.util.ArrayList;
import java.util.List;

public class Secretary implements Subject {

    private List<Observer> observerList = new ArrayList<>();

    private String action;

    @Override
    public void attach(Observer observer) {
        this.observerList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        this.observerList.remove(observer);
    }

    @Override
    public void notifyAction() {
        for (Observer observer : observerList) {
            observer.update();
        }
    }

    @Override
    public String getSubjectState() {
        return action;
    }

    @Override
    public void setSubjectState(String state) {
        this.action = state;
    }
}
